#include "mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QWidget(parent)
{
    copyD = new CopyDialog;
    fList = new FileList;
    drop = new Drop;
    base64 = new CryptBase64::crypt;
    hb = new QHBoxLayout;

    hb->addWidget(drop);
    hb->addWidget(fList);

    setLayout(hb);

    setFixedSize(600,300);

    connect(drop,SIGNAL(dropFile(QString)),this,SLOT(loadFile(QString)));
    connect(fList,SIGNAL(doubleClicked(QModelIndex)),this,SLOT(openCopyDialog(QModelIndex)));
}

void MainWindow::loadFile(const QString &filename)
{
    QFile file(filename);

    if(file.open(QIODevice::ReadOnly))
    {
        QByteArray cryptedData = base64->encoding(file.readAll());
        fList->addItem(filename);
        encodeString << QString(cryptedData);
    }

    file.close();
}

void MainWindow::openCopyDialog(const QModelIndex &modelI)
{
    copyD->loadData(encodeString[modelI.row()]);
}

MainWindow::~MainWindow()
{
    qDebug()<<"Destructor";

    delete copyD;
    delete base64;
}
